//
//  HWAboutUsGuanYuViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/10/28.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWAboutUsGuanYuViewController.h"
#import "HWTongYongSheZhiTableViewCell.h"
@interface HWAboutUsGuanYuViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UIView *headView;

@property(strong,nonatomic) NSArray *dataArr;
@property(strong,nonatomic) NSMutableArray *rightMuArr;
@property(strong,nonatomic) NSDictionary *dataDic;

@property(strong,nonatomic) UIView *footview;
@property(strong,nonatomic) UIImageView *erwiamtupianimageView;

@property(strong,nonatomic) WKWebView *webView;

@end

@implementation HWAboutUsGuanYuViewController

-(UITableView *)mainaTableVie {
    
    if  (_mainaTableVie == nil) {
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        _mainaTableVie.backgroundColor = RGB(247, 247, 247);
        
    }
    return   _mainaTableVie ;
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self navigationView];
    [self setupUI];
    [self addheadeViewOrfootView];
    
    //发送网络请求
    [self fasongwangluoqingqiu];
    
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)navigationView {
    
    //  self.navigationItem.title = @"关于我们";
    
    self.navigationItem.title = [HWjianzhiduiObject keylocalization:@"关于我们"];
    
    
    //   self.dataArr = @[@"接收活动消息",@"聊天消息通知栏提醒",@"接收领积分提醒",@"自动检查版本更新",@"省流量",@"清理缓存"];
    
    //  self.dataArr = @[@"工作时间",@"客服电话",@"客服QQ"];
    
    //    self.dataArr = @[[HWjianzhiduiObject keylocalization:@"工作时间"],[HWjianzhiduiObject keylocalization:@"客服电话"],[HWjianzhiduiObject keylocalization:@"客服QQ"]];
    //
    //    self.rightMuArr =  [[NSMutableArray alloc]init];
    
    
    
    
}



- (void)setupUI {
    
    //    self.view.backgroundColor = [UIColor redColor];
    //    [self.view addSubview:self.mainaTableVie];
    
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    configuration.userContentController = [[WKUserContentController alloc] init];
    // [configuration.userContentController addScriptMessageHandler:self name:@"gameinfo"];
    
    NSString *str = self.dataDic[@"update_log"];
    
    _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenW-80,240) configuration:configuration];
    //     _webView.UIDelegate = self;
    //     _webView.navigationDelegate = self;
    //    _webView.hidden = YES;
    //
    //     _webView.scrollView.scrollEnabled = YES;
    [self.view addSubview:self.webView];
    [_webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
}

//
- (void)addheadeViewOrfootView  {
    
    self.headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 150)];
    self.mainaTableVie.tableHeaderView = self.headView;
    
    UIImageView *icoimageView = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenW-52)/2, 40, 52, 52)];
    icoimageView.backgroundColor = [UIColor clearColor];
    icoimageView.layer.cornerRadius = 8;
    icoimageView.layer.masksToBounds = YES;
    [self.headView addSubview:icoimageView];
    
    NSDictionary *dic =  [[NSBundle mainBundle] infoDictionary];
    NSString *icostr =     dic[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconName"];
    //UIImage *appIcon = [UIImage imageNamed: [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectAtIndex:0]];
    UIImage  *appIcon = [UIImage imageNamed:icostr];
    appIcon = [UIImage imageNamed:@"AppIcon"];
    icoimageView.image = appIcon;
    
    
    
    
    
    self.footview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 180)];
    
    self.mainaTableVie.tableFooterView = self.footview ;
    
    
    UIImageView *icoimageView1 = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenW-116)/2, 40, 116, 116)];
    icoimageView1.backgroundColor = [UIColor clearColor];
    //    icoimageView.layer.cornerRadius = 8;
    //    icoimageView.layer.masksToBounds = YES;
    self.erwiamtupianimageView = icoimageView1;
    [self.footview addSubview:icoimageView1];
    
    
    
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,icoimageView1.bottom+10, kScreenW-40, 22)];
    //     nameLabel.text = fanlilistArr[i];
    //  nameLabel.backgroundColor =  RGB(248, 119, 6);
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.font = [UIFont systemFontOfSize:15];
    nameLabel.textColor = RGB(68, 68, 68);
    //     nameLabel.layer.cornerRadius = 8;
    //     nameLabel.layer.masksToBounds = YES;
    nameLabel.text = @"微信公众号";
    nameLabel.text = [HWjianzhiduiObject keylocalization:@"微信公众号"];
    
    [self.footview addSubview:nameLabel];
    
    
    
    
    
    
    
    
}




// 发送网路请求
- (void)fasongwangluoqingqiu {
    
    
    //    NSString *userID = [HWLocallyStoredData getLoginUserID];
    //    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    //    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    //    NSString *signMD5 = [WMUtil md5HexDigest:sign];
    NSDictionary *parametes = @{
        @"ct" :  @"app",
        @"ac" : @"contact",
        @"ios" : @"1",
        @"member_id":[HWLocallyStoredData getCode],
        @"h5":@"1",
        @"version":[NSString stringWithFormat:@"%@(%@)",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]
        
    };
    
    NSArray *allKeys = [parametes allKeys];
    NSArray *allValues = [parametes allValues];
    NSString *logUrl = @"";
    for (int i = 0; i < allKeys.count; i ++) {
        if (i == 0) {
            logUrl = [NSString stringWithFormat:@"%@?%@=%@",[HWOCGlobalConst baseUrl],allKeys[i],allValues[i]];
        } else {
            logUrl = [NSString stringWithFormat:@"%@&%@=%@",logUrl,allKeys[i],allValues[i]];
        }
    }
    
    [_webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:logUrl]] ];
    
    //    [MBProgressHUD show:@"正在绑定邮箱"];
    
    //             [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
    //
    //
    //                 NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
    //              //   [MBProgressHUD hideHUD];
    //
    //
    //                 if ([codeStr intValue] == 1) {
    //
    //
    //
    //                     self.dataDic = response[@"data"];
    //
    //                     [self.rightMuArr addObject:self.dataDic[@"working_time"]];
    //                       [self.rightMuArr addObject:self.dataDic[@"phone"]];
    //                       [self.rightMuArr addObject:self.dataDic[@"qq"]];
    //
    //
    //
    //                     [self.erwiamtupianimageView sd_setImageWithURL:[NSURL URLWithString:self.dataDic[@"weixin"]] placeholderImage:nil];
    //
    //
    //
    //                     [self.mainaTableVie reloadData];
    //
    //
    //                 } else {
    //
    //                      [MBProgressHUD  showSuccess:response[@"message"]];
    //
    //                 }
    //                 NSLog(@"%@",response);
    //
    //
    //             } failure:^(NSString *error) {
    //
    //                 [MBProgressHUD  showError:@"查询失败"];
    //
    //
    //             }];
    
    
    
}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return  1;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return  self.dataArr.count;
    
    
    
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *cellID = @"cellID";
    
    HWTongYongSheZhiTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell =  [[NSBundle mainBundle] loadNibNamed:@"HWTongYongSheZhiTableViewCell" owner:nil options:nil].firstObject;
        
    }
    
    cell.selectionStyle  = UITableViewCellSelectionStyleNone;
    cell.biaotiNamaLabel.text =  self.dataArr[indexPath.row];
    
    cell.biaotiNamaLabel.textColor = RGB(68, 68, 68);
    
    cell.zuobianleironLabel.hidden = NO;
    cell.xuanzhongSwitch.hidden = YES;
    
    if (self.rightMuArr.count  ==  3 ) {
        cell.zuobianleironLabel.text = [NSString stringWithFormat:@"%@",self.rightMuArr[indexPath.row]];
    }
    
    
    
    
    return  cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  64;
    
    
}




@end
